package cc.wsyw126.java.schedule;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by junpeng.yang on 16/11/18.
 */
public class TimerSchedule {
    public static void task_4() {
        TimerTask task = new TimerTask() {

            @Override
            public void run() {
                System.out.println("execute task:" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Calendar.getInstance().getTime()));
                try {
                    Thread.sleep(6000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "定时任务已启动！");
            }
        };

        new Timer().scheduleAtFixedRate(task, 0, 3000);
    }

    public static void main(String[] args) {
        task_4();
    }
}
